june 23, 2020
horses <- read_csv("../data/horses.csv")
glimpse(horses)
Rows: 50 Columns: 6 $ X1 <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18… $ HorseID <dbl> 97, 156, 56, 139, 65, 184, 88, 182, 101, 135, 35, 39, 198, 10… $ Price <dbl> 38000, 40000, 10000, 12000, 25000, 35000, 35000, 12000, 22000… $ Age <dbl> 3, 5, 1, 8, 4, 8, 5, 17, 4, 6, 7, 7, 14, 6, 3, 6, 6, 12, 7, 7… $ Height <dbl> 16.75, 17.00, NA, 16.00, 16.25, 16.25, 16.50, 16.75, 17.25, 1… $ Sex <chr> "m", "m", "m", "f", "m", "f", "m", "f", "m", "f", "m", "f", "…
ggplot(data = horses, aes(x = Age, y = Price))
ggplot(data = horses, aes(x = Age, y = Price)) + geom_point()
ggplot(data = horses, aes(x = Age, y = Price)) + geom_point() + geom_smooth(method = "lm", se= F)
ggplot(data = horses, aes(x = Age, y = Price)) + geom_point() + geom_smooth(method = "lm", formula = y ~ x + I(x^2), se = F )
ggplot(data = horses, aes(x = Age, y = Price, colour = Sex)) + geom_point() + geom_smooth(method = "lm", formula = y ~ x + I(x^2), se = F )
ggplot(data = horses, aes(x = Age, y = Price, colour = Sex)) +
geom_point() +
geom_smooth(method = "lm", se = F, formula = y ~ x + I(x^2), fullrange = T ) +
ggthemes::theme_clean() +
scale_y_continuous(labels = scales::dollar_format(prefix = "$")) +
ggthemes::scale_color_colorblind(labels = c("Female", "Male") ) +
labs(y = "Price (in US Dollar)",
x = "Age (in years)") +
theme(legend.position = "bottom",
legend.justification = "right",
axis.title = element_text(hjust = 0))
| Data set | Mean | SD | Mean | SD |
|---|---|---|---|---|
| 1 | 9 | 3.32 | 7.5 | 2.03 |
| 2 | 9 | 3.32 | 7.5 | 2.03 |
| 3 | 9 | 3.32 | 7.5 | 2.03 |
| 4 | 9 | 3.32 | 7.5 | 2.03 |
tdd <- read_csv("../data/tdd.csv")
summary(tdd)
dataset x y Min. : 1 Min. :15.56 Min. : 0.01512 1st Qu.: 4 1st Qu.:41.07 1st Qu.:22.56107 Median : 7 Median :52.59 Median :47.59445 Mean : 7 Mean :54.27 Mean :47.83510 3rd Qu.:10 3rd Qu.:67.28 3rd Qu.:71.81078 Max. :13 Max. :98.29 Max. :99.69468
mammals <- read_csv("../data/mammals.csv") %>%
rename(species = X1)
glimpse(mammals)
Rows: 62 Columns: 3 $ species <chr> "Arctic fox", "Owl monkey", "Mountain beaver", "Cow", "Grey w… $ body <dbl> 3.385, 0.480, 1.350, 465.000, 36.330, 27.660, 14.830, 1.040, … $ brain <dbl> 44.50, 15.50, 8.10, 423.00, 119.50, 115.00, 98.20, 5.50, 58.0…
ggplot(data = horses, mapping = aes(y = Price, x = Age, colour = Sex))
ggplot(data = horses, mapping = aes(y = Price, x = Age, colour = Sex)) + geom_point()
ggplot(data = horses, mapping = aes(y = Price, x = Age, colour = Sex)) + geom_smooth(method = "lm")
ggplot(data = horses, mapping = aes(y = Price, x = Age, colour = Sex)) + geom_point() + geom_smooth(method = "lm")
ggplot(data = horses, aes(y = Price, x = Age))
ggplot(data = horses, aes(y = Price, x = Age)) + geom_point(size = .5)
ggplot(data = horses, aes(y = Price, x = Age)) + geom_point(size = .5) + facet_grid( ~ Sex)
ggplot(data = horses, aes(y = Price, x = Age)) + geom_point(size = .5) + facet_grid( ~ Sex) + stat_smooth(method = "lm", se = FALSE, fullrange = TRUE)
ggplot(data = horses, aes(y = Price, x = Age)) + geom_point(size = .5) + facet_grid( ~ Sex) + stat_smooth(method = "lm", se = FALSE, fullrange = TRUE) + coord_fixed(ratio = 2/25000)
ggplot(data = horses, aes(y = Price, x = Age)) + geom_point(size = .5) + facet_grid( ~ Sex) + stat_smooth(method = "lm", se = FALSE, fullrange = TRUE) + coord_trans(x = "log", y = "reverse")
ggplot(data = horses, aes(y = Price, x = Age)) + geom_point(size = .5) + facet_grid( ~ Sex) + stat_smooth(method = "lm", se = FALSE, fullrange = TRUE) + coord_flip()
ggplot(data = horses, aes(y = Price, x = Age)) + geom_point(size = .25) + facet_grid( ~ Sex) + stat_smooth(method = "lm", se = FALSE, fullrange = TRUE) + theme_dark()
ggplot(data = horses, aes(y = Price, x = Age)) + geom_point(size = .25) + facet_grid( ~ Sex) + stat_smooth(method = "lm", se = FALSE, fullrange = TRUE) + theme(panel.background = element_blank())
weight <- read_csv("../data/weight.csv")
glimpse(weight)
Rows: 6,067 Columns: 8 $ subjectid <dbl> 10027, 10032, 10033, 10092, 10093, 10115, 10117, 10… $ gender <chr> "Male", "Male", "Male", "Male", "Male", "Male", "Ma… $ height <dbl> 177.6, 170.2, 173.5, 165.5, 191.4, 172.0, 181.0, 18… $ height_selfreport <dbl> 180.34, 172.72, 172.72, 167.64, 195.58, 175.26, 182… $ weight <dbl> 81.5, 72.6, 92.9, 79.4, 94.6, 80.2, 116.2, 95.4, 99… $ weight_selfreport <dbl> 81.66969, 72.59528, 93.01270, 79.40109, 96.64247, 7… $ age <dbl> 41, 35, 42, 31, 21, 39, 32, 23, 36, 23, 32, 28, 36,… $ race <dbl> 1, 1, 2, 1, 2, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, …
ggplot(horses, aes(y = Price, x = Age)) + geom_point(colour = "red")
ggplot(horses, aes(y = Price, x = Age)) + geom_point(aes(colour = "red"))
ggplot(horses, aes(y = Price, x = Age)) + geom_point(aes(colour = Sex))
ggplot(horses, aes(y = Price, x = Age)) + geom_point(aes(colour = Sex)) + geom_smooth(method = "lm")
ggplot(horses, aes(y = Price, x = Age)) + geom_point() + geom_smooth(aes(colour = Sex), method = "lm")
ggplot(horses, aes(y = Price, x = Age)) + geom_point(aes(colour = Sex)) + geom_smooth(aes(colour = Sex), method = "lm")
ggplot(horses, aes(y = Price, x = Age, colour = Sex)) + geom_point() + geom_smooth(method = "lm")
ggplot(horses, aes(y = Price, x = Age, colour = Sex)) + geom_point(size = 2)
ggplot(horses, aes(y = Price, x = Age, shape = Sex)) + geom_point(size = 2)
ggplot(horses, aes(y = Price, x = Age, colour = Sex, shape = Sex)) + geom_point(size = 2)
x, y, shape, colour, size, fill, alpha, stroke, group
x, y, colour, fill, size, linetype, alpha, group
x, y, lower, xlower, upper, xupper, middle, xmiddle, ymin, xmin, ymax, xmax, weight, colour, fill, size, alpha, shape, linetype, group
(Wong 2010, 665)
ggplot(data = horses, aes(x = Age, y = Price)) + geom_point(size = 3) + facet_grid(~Sex)
ggplot(data = horses, aes(x = Age, y = Price)) + geom_point(size = 3) + facet_wrap(~Sex, scales = "free_y")
ggplot(data = horses, aes(x = Age, y = Sex, colour = Price)) + geom_point(size = 3)
ggplot(data = horses, aes(x = Age, y = Sex, size = Price)) + geom_point()
ggplot(data = horses, aes(x = Age, y = Price,
colour = Sex)) +
geom_point(size = 3)
ggplot(data = horses, aes(x = Age, y = Price,
label = Sex)) +
geom_text(size = 3)
ggplot(data = horses, aes(x = Age, y = Price,
shape = Sex)) +
geom_point(size = 3)
ggplot(data = horses, aes(x = Age, y = Price,
colour = Sex)) +
geom_smooth(method = "lm", se = F)
ggplot(data = horses, aes(x = Age, y = Price,
linetype = Sex)) +
geom_smooth(method = "lm", se = F)
ggplot(data = horses, aes(x = Age, y = Price,
size = Sex)) +
geom_smooth(method = "lm", se = F)
[1] "abline" "area" "bar" "bin2d" [5] "blank" "boxplot" "col" "column" [9] "contour" "contour_filled" "count" "crossbar" [13] "curve" "density" "density_2d" "density2d" [17] "dotplot" "errorbar" "errorbarh" "freqpoly" [21] "hex" "histogram" "hline" "jitter" [25] "label" "line" "linerange" "map" [29] "path" "point" "pointrange" "polygon" [33] "qq" "qq_line" "quantile" "raster" [37] "rect" "ribbon" "rug" "segment" [41] "sf" "sf_label" "sf_text" "smooth" [45] "spoke" "step" "text" "tile" [49] "violin" "vline"
ggplot(data = horses, aes(x = Sex)) + geom_bar()
ggplot(data = horses, aes(x = Price)) + geom_histogram()
ggplot(data = horses, aes(x = Price)) + geom_density()
ggplot(data = horses, aes(y = Price, x = Age,
colour = Sex)) +
geom_point() +
labs()
ggplot(data = horses, aes(y = Price, x = Age,
colour = Sex)) +
geom_point() +
labs(title = "My scatter plot")
ggplot(data = horses, aes(y = Price, x = Age,
colour = Sex)) +
geom_point() +
labs(title = "My scatter plot",
subtitle = "I'm a subtitle")
ggplot(data = horses, aes(y = Price, x = Age,
colour = Sex)) +
geom_point() +
labs(caption = "Caption for data source")
ggplot(data = horses, aes(y = Price, x = Age,
colour = Sex)) +
geom_point() +
labs(tag = "A")
ggplot(data = horses, aes(y = Price, x = Age,
colour = Sex)) +
geom_point() +
labs(x = "Age of horse",
y = "Price of horse in $")
ggplot(data = horses, aes(y = Price, x = Age,
colour = Sex)) +
geom_point() +
labs(colour = "Legend\ntitle:")
ggplot(data = horses, aes(y = Price, x = Age,
colour = Sex)) +
geom_point() +
scale_colour_discrete(labels = c("female", "male"))
ggplot(data = horses, aes(y = Price, x = Age,
colour = Sex)) +
geom_point() +
scale_colour_manual(labels = c("female", "male"),
values = c("darkseagreen", "firebrick"))
ggplot(data = horses, aes(y = Price, x = Age,
colour = Sex)) +
geom_point() +
scale_colour_manual(labels = c("female", "male"),
values = c("darkseagreen3", "firebrick1"))
mycolours = c("#000000", "#E69F00", "#56B4E9",
"#009E73", "#F0E442", "#0072B2",
"#D55E00", "#CC79A7")ggplot(data = horses, aes(y = Price, x = Age,
colour = Sex)) +
geom_point() +
scale_colour_manual(labels = c("female", "male"),
values = mycolours[c(1,2)])
ggplot(data = horses, aes(y = Price, x = Age,
colour = Sex)) +
geom_point() +
scale_colour_colorblind(labels = c("female", "male"))
ggplot(data = horses, aes(y = Price, x = Age)) + geom_point() + facet_grid(~Sex)
horses$Sex <- recode(horses$Sex, f = "female", m = "male")
ggplot(data = horses, aes(y = Price, x = Age)) + geom_point() + facet_grid(~Sex)
ggplot(data = horses, aes(y = Price, x = Age)) + geom_point() + facet_grid(~Sex, labeller = label_both)
[1] "theme_bw" "theme_classic" "theme_dark" "theme_grey" [5] "theme_light" "theme_linedraw" "theme_minimal" "theme_void"
ggplot(data = horses, aes(y = Price, x = Age)) + geom_point() + facet_grid(~Sex) + theme_grey(base_size = 14)
ggplot(data = horses, aes(y = Price, x = Age)) + geom_point() + facet_grid(~Sex) + theme_minimal(base_size = 14)
ggplot(data = horses, aes(y = Price, x = Age)) + geom_point() + facet_grid(~Sex) + theme_light(base_size = 14)
ggplot(data = horses, aes(y = Price, x = Age)) + geom_point() + theme()
ggplot(data = horses, aes(y = Price, x = Age)) + geom_point() + theme(axis.text = element_text(face = "bold"))
ggplot(data = horses, aes(y = Price, x = Age)) + geom_point() + theme(axis.title = element_text(face = "bold"))
ggplot(data = horses, aes(y = Price, x = Age)) + geom_point() + theme(axis.title.y = element_text(face = "bold"))
ggplot(data = horses, aes(y = Price, x = Age,
colour = Sex)) +
geom_point() +
theme()
ggplot(data = horses, aes(y = Price, x = Age,
colour = Sex)) +
geom_point() +
theme(legend.position = "top")
ggplot(data = horses, aes(y = Price, x = Age,
colour = Sex)) +
geom_point() +
theme(legend.position = "top",
legend.justification = "right")
ggplot(data = horses, aes(y = Price, x = Age,
colour = Sex)) +
geom_point() +
theme(legend.position = c(.9,.8))
ggplot(data = horses, aes(y = Price, x = Age)) + geom_point() + theme()
ggplot(data = horses, aes(y = Price, x = Age)) + geom_point() + theme(panel.background = element_blank())
ggplot(data = horses, aes(y = Price, x = Age)) + geom_point() + theme()
ggplot(data = horses, aes(y = Price, x = Age)) + geom_point() + theme(plot.background = element_rect(fill = "pink"))
ggplot(data = horses, aes(y = Price, x = Age)) + geom_point() + labs(title = "I'm a title") + theme(plot.title = element_text(colour = "pink"))
ggplot(data = horses, aes(y = Price, x = Age)) + geom_point() + labs(caption = "I'm a caption") + theme(plot.caption = element_text(face = "italic"))
ggplot(data = horses, aes(y = Price, x = Age)) + geom_point() + theme(plot.margin = unit(c(2,2,2,2), "cm"))
ggplot(data = horses, aes(y = Price, x = Age)) + geom_point() + facet_grid(~Sex, labeller = label_both) + theme()
ggplot(data = horses, aes(y = Price, x = Age)) + geom_point() + facet_grid(~Sex, labeller = label_both) + theme(strip.background = element_blank())
ggplot(data = horses, aes(y = Price, x = Age)) + geom_point() + facet_grid(~Sex, labeller = label_both) + theme(strip.background = element_rect(fill = "forestgreen"))
ggplot(data = horses, aes(y = Price, x = Age)) +
geom_point() +
facet_grid(~Sex, labeller = label_both) +
theme(strip.background = element_rect(fill = "forestgreen"),
strip.text = element_text(colour = "white", hjust = 0))
ggplot(data = horses, aes(y = Price, x = Age)) +
geom_point() +
facet_grid(~Sex, labeller = label_both) +
theme(strip.background = element_rect(fill = "forestgreen"),
strip.text = element_text(colour = "white", hjust = 0,
face = "bold", size = 16, angle = 180))
Allison, Truett, and Domenic V. Cicchetti. 1976. “Sleep in Mammals: Ecological and Constitutional Correlates.” Science 194 (4266). American Association for the Advancement of Science: 732–34.
Anscombe, Francis J. 1973. “Graphs in Statistical Analysis.” The American Statistician 27. Taylor & Francis Group: 17–21.
Davis, Caroline. 1990. “Body Image and Weight Preoccupation: A Comparison Between Exercising and Non-Exercising Women.” Appetite 15 (1). Elsevier: 13–21.
Fox, John, and Sanford Weisberg. 2011. An R Companion to Applied Regression. Vol. 2. Sage.
Hartwig, Frederick, and Brian E. Dearing. 1979. Exploratory Data Analysis. 16. Sage.
Matejka, Justin, and George Fitzmaurice. 2017. “Same Stats, Different Graphs: Generating Datasets with Varied Appearance and Identical Statistics Through Simulated Annealing.” In Proceedings of the 2017 Chi Conference on Human Factors in Computing Systems, 1290–4.
Tufte, Edward R. 1983. The Visual Display of Information. Cheshire, Ct: Graphics Press.
———. 1989. The Visual Display of Quantitative Information. Vols. 13 – 14. Graphic Press.
Tukey, John W. 1977. Exploratory Data Analysis. Vol. 2.
Weisberg, S. 1985. Applied Linear Regression. Vol. 2. New York: John Wiley.
Wickham, Hadley. 2010. “A Layered Grammar of Graphics.” Journal of Computational and Graphical Statistics 19 (1). Taylor & Francis: 3–28.
———. 2016. Ggplot2: Elegant Graphics for Data Analysis. Springer.
Wilkinson, Leland. 1999. The Grammar of Graphics. Springer.
Wong, Bang. 2010. “Points of View: Design of Data Figures.” Nature Methods 7 (9). Nature Publishing Group: 665.